﻿using UnityEngine;
using UnityEngine.UI;

public class TopLoadingPanel : MonoBehaviour
{
    public Image imgProgress;
    public Text textProgress;

    private float _currentProgress;

    private void OnEnable()
    {
        _currentProgress = 0;
        RefreshProgress();
    }

    private void OnDisable()
    {
        _currentProgress = 0;
        RefreshProgress();
    }

    void RefreshProgress()
    {
        imgProgress.fillAmount = _currentProgress;
        textProgress.text = $"{_currentProgress * 100}%";
    }

    public void SetActiveAndProgress(bool active, float progress)
    {
        if (active)
        {
            gameObject.SetActive(true);
            _currentProgress = progress;
            RefreshProgress();
        }
        else
        {
            gameObject.SetActive(false);
        }
    }
}